
import java.util.*;
public class Main
{
    public static boolean isprim(long x) {
        if(x < 2) return false;
        for(int i = 2; i <= Math.sqrt(x); i++) {
            if(x % i == 0)
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- != 0) {
            long a = in.nextLong(), b = in.nextLong();
            if((a == 1 && isprim(b)) || (b == 1 && isprim(a))) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}
